#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/1/20 14:15
# @Author  : shwy
# @Site    : http://ishwy.me
# @File    : User.py
# @Software: PyCharm
# 用户控制层
from blog.model.User import User
from blog.config import *

from blog import app,db
from flask import request,render_template,url_for,redirect,Flask


# 用户注册
@app.route('/reg',methods=['GET','POST'])
def reg():

    # 这里去接受 post 参数，并写入到数据库
    if request.method == 'POST':

        username =  request.form['username']
        password =  request.form['password']

        app.logger.debug('username arg %s ' % username)
        app.logger.debug('password arg %s ' % password)

        # 插入数据

        inset = User(username= username, password= password)
        db.session.add(inset)
        db.session.commit()

        return render_template(common_path +'result.html',username= username, password= password)
        # return 'Username is %s ' % username + '\r\n Password is %s' % password

    return render_template(user_path + 'reg.html')